package com.hjxr.quota.theme.controller;

import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.hjxr.quota.util.PageUtil;
import com.hjxr.quota.theme.domain.QuotaThemeZone;
import com.hjxr.quota.theme.service.IQuotaThemeZoneService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;

/**
 * zoneController
 *
 * @author wanxiaochao
 * @date 2020-09-02
 */
@RestController
@RequestMapping("/zone")
@Api(tags = "主题域处理接口")
public class QuotaThemeZoneController extends ApiController {
    @Resource
    private IQuotaThemeZoneService quotaThemeZoneService;

    /**
     * 查询zone列表
     */
    @GetMapping("/list")
    @ApiOperation("主题域列表")
    public R<PageUtil> list(@RequestParam Map<String, Object> params) {
        return success(quotaThemeZoneService.selectQuotaThemeZoneList(params));
    }

    @GetMapping("/listCtSet")
    @ApiOperation("主题域加主题集数")
    public R<PageUtil> listCtSet(@RequestParam Map<String, Object> params) {
        return success(quotaThemeZoneService.selectZoneAndSetTreeList(params));
    }

    /**
     * 获取zone详细信息
     */
    @ApiOperation("主题域详情")
    @GetMapping(value = "/{id}")
    public R<QuotaThemeZone> getInfo(@PathVariable("id") Integer id) {
        return success(quotaThemeZoneService.selectQuotaThemeZoneById(id));
    }

    /**
     * 新增zone
     */
    @PostMapping
    @ApiOperation("新增主题域")
    public R<Boolean> add(@RequestBody QuotaThemeZone quotaThemeZone) {
        quotaThemeZone.setCreateDate(new Date());
        return success(quotaThemeZoneService.save(quotaThemeZone));
    }

    /**
     * 修改zone
     */
    @PutMapping
    @ApiOperation("修改主题域")
    public R<Integer> edit(@RequestBody QuotaThemeZone quotaThemeZone) {
        return success(quotaThemeZoneService.updateQuotaThemeZone(quotaThemeZone));
    }

    /**
     * 删除zone
     */
    @DeleteMapping("/{ids}")
    @ApiOperation("删除主题域")
    public R<Integer> remove(@PathVariable Integer[] ids) {
        return success(quotaThemeZoneService.deleteQuotaThemeZoneByIds(ids));
    }
}
